# 字典 键值对 key值不可重复
mydict = {}
print(type(mydict))
mydict = {
    "张三": 99,
    "张三": 19,  # 重复的key值只保留最后一个
    "李四": 88
}
print(mydict)

# 获取值
print(mydict["张三"])

# 字典的嵌套
# key值需要是不可修改的(列表、字典等不可以，元组可以)
mydict = {
    "Tom": {
        "aa": 12,
        "bb": 22
    }, "Mary": {
        "cc": 99
    }, "Amy": {
        "dd": 999,
        'e': 898989,
        "ff": 1
    }, 88: {
        7878: 1,
        "(2, 3)": "you!"
    }
}
print(mydict["Tom"])
print(mydict["Tom"]["bb"])
print(mydict[88], mydict[88]["(2, 3)"])

# 字典的新增与更新
mydict[12] = 888
print(mydict)
mydict["Tom"] = {}
print(mydict)

# 字典的删除
del_element = mydict.pop("Amy")
print(mydict)
print(type(del_element), del_element)

# 字典的清空
del_element.clear()
print(del_element)

# 获取全部key
keys = mydict.keys()
print(type(keys), keys)

# 字典的遍历
# 1、使用keys
for key in keys:
    print(f"1: key:{key}\tvalue:{mydict[key]}")

# 2、直接遍历
for key in mydict:
    print(f"2: key:{key}\tvalue:{mydict[key]}")

# 统计字典元素数量
print(len(mydict))
